** Generating Tables and Plots of
** MTurk Conjoint Experiment 

*********************
* Stata preliminaries
*********************

clear all
set more off
version 14

* change this to fit your directory structure
global path "~/Dropbox/0001 Academic Projects/Ongoing/0148 The Cyber/Posted/FPA Version/Work"
log using "$path/Logs/Figure4Figure5Log.log", replace

cd "$path/Data/"
use "TheCyber2019AnalysisData.dta"

lab var college "College"
lab var female "Female"
lab var republican3 "Republican"
lab var democrat3 "Democrat"
lab var independent3 "Independent"
lab var republican7 "Republican"
lab var democrat7 "Democrat"
lab var independent7 "Independent"

set scheme plotplainblind

******************************************
* Confidence Coefficient Plots And Tables
******************************************
cd "$path/Charts/"

quietly reg confident white age college female republican7 i.target i.economic i.death ///
	i.confidence i.aggressortype i.aggressororigin i.purpose i.indconcur ///
	i.policymakertype##i.policymakerconcur task choice, vce(cluster caseid)
eststo confidencemodel

coefplot, drop(_cons age white college female republican7 task choice) xline(0) ///
headings (0.target = "{bf:Target}" 0.economic = "{bf:Economic}" ///
		0.death = "{bf:Deaths}" 0.confidence = "{bf:Intel Community Confidence}" ///
		0.aggressortype = "{bf:Aggressor Type}" ///
		0.aggressororigin = "{bf:Aggressor Origin}" ///
		0.purpose = "{bf:Purpose}" ///
		0.indconcur = "{bf:Independent Experts}" ///
		0.policymakertype = "{bf:Policymaker ID}" ///
		0.policymakerconcur = "{bf:Policymaker Cue}") ///
		coeflabels(,labsize(tiny)) ///
		title("Figure 4: OLS Coefficients for" "Respondents' Confidence in Attribution",size(small)) ///
		omitted baselevels ///
		xsize(6) ysize(7)
graph export "Figure 4.pdf", replace
		
			
** By party ID
* PID7 (leaners included with Party)
quietly reg confident white age college female  i.target i.economic i.death ///
	i.confidence i.aggressortype i.aggressororigin i.purpose i.indconcur ///
	i.policymakertype##i.policymakerconcur task choice if republican7 == 1, vce(cluster caseid)
eststo confidencemodelGOP

quietly reg confident white age college female  i.target i.economic i.death ///
	i.confidence i.aggressortype i.aggressororigin i.purpose i.indconcur ///
	i.policymakertype##i.policymakerconcur task choice if democrat7 == 1, vce(cluster caseid)
eststo confidencemodelDEM
		
	
#delimit ;
coefplot 
	(confidencemodelGOP, label(Republicans) offset(.08)) (confidencemodelDEM, label(Democrats) offset(-.08)), 
	drop(_cons age white college female republican7 task choice *.target *.economic *.death *.aggressortype *.aggressororigin *.purpose) ///
		xline(0) ///
		headings (0.target = "{bf:Target}" 0.economic = "{bf:Economic}" ///
		0.death = "{bf:Deaths}" 0.confidence = "{bf:Intel Community Confidence}" ///
		0.aggressortype = "{bf:Aggressor Type}" ///
		0.aggressororigin = "{bf:Aggressor Origin}" ///
		0.purpose = "{bf:Purpose}" ///
		0.indconcur = "{bf:Independent Experts}" ///
		0.policymakertype = "{bf:Policymaker ID}" ///
		0.policymakerconcur = "{bf:Policymaker Cue}") ///
		coeflabels(,labsize(tiny)) ///
		title("Figure 5: OLS Coefficients for Respondents' Confidence""in Attribution, by Party ID",size(small)) ///
		 baselevels ///
		xsize(8) ysize(7) ///
		legend(cols(2) position(12))
;

graph display, ysize(3) xsize(3)
;		
		
graph export "Figure 5.pdf", replace
;

#delimit cr		
				
** By party ID
* PID3 (alternative specification, leaners treated as independents)
quietly reg confident white age college female  i.target i.economic i.death ///
	i.confidence i.aggressortype i.aggressororigin i.purpose i.indconcur ///
	i.policymakertype##i.policymakerconcur task choice if republican3 == 1, vce(cluster caseid)
eststo confidencemodelGOP

quietly reg confident white age college female  i.target i.economic i.death ///
	i.confidence i.aggressortype i.aggressororigin i.purpose i.indconcur ///
	i.policymakertype##i.policymakerconcur task choice if democrat3 == 1, vce(cluster caseid)
eststo confidencemodelDEM
		
	
#delimit ;
coefplot 
	(confidencemodelGOP, label(Republicans) offset(.08)) (confidencemodelDEM, label(Democrats) offset(-.08)), 
	drop(_cons age white college female republican3 task choice *.target *.economic *.death *.aggressortype *.aggressororigin *.purpose) ///
		xline(0) ///
		headings (0.target = "{bf:Target}" 0.economic = "{bf:Economic}" ///
		0.death = "{bf:Deaths}" 0.confidence = "{bf:Intel Community Confidence}" ///
		0.aggressortype = "{bf:Aggressor Type}" ///
		0.aggressororigin = "{bf:Aggressor Origin}" ///
		0.purpose = "{bf:Purpose}" ///
		0.indconcur = "{bf:Independent Experts}" ///
		0.policymakertype = "{bf:Policymaker ID}" ///
		0.policymakerconcur = "{bf:Policymaker Cue}") ///
		coeflabels(,labsize(tiny)) ///
		title("OLS Coefficients for Respondents' Confidence in Attribution,""by Party ID",size(small)) ///
		 baselevels ///
		xsize(8) ysize(3) ///
		legend(cols(2) position(12))
;

graph display, ysize(3) xsize(3)
;				
		
graph export AppendixConjointQualtricsConjointResultsSevereConfidentByPID3.pdf, replace 

;

#delimit cr


*************************************************************
* Tables

cd "$path/Tables/"


esttab confidencemodel confidencemodelGOP confidencemodelDEM ///
	using Fig3Fig4TablePID7.tex, ///
	label replace nobaselevels ///
	interaction(" X ") wrap  onecell compress ///
	mtitles("Main Model" "Republicans" "Democrats") longtable ///
	title("Full Results of Conjoint OLS Model")
	


lab var college "College"
lab var female "Female"
lab var republican3 "Republican"
lab var democrat3 "Democrat"
lab var independent3 "Independent"
lab var republican7 "Republican"
lab var democrat7 "Democrat"
lab var independent7 "Independent"

gen perceivedlikely = .
replace perceivedlikely = cyberLikelyPowerGrid if target == 3
replace perceivedlikely = cyberLikelyMilitary if target == 4
replace perceivedlikely = cyberLikelyMajorCorps if target == 0
replace perceivedlikely = cyberLikelyMajorCorps if target == 1

lab var perceivedlikely "Likely Target Vulnerability"
lab val perceivedlikely threatpossibility

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* By Views of Sector Vulnerability
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

quietly reg confident i.aggressororigin i.target i.economic i.death i.confidence ///
		i.aggressortype i.purpose i.indconcur policymakertype##policymakerconcur ///
		female republican7  college white age task choice, vce(cluster caseid)
eststo confBase
		
quietly reg confident i.aggressororigin i.target i.economic i.death i.confidence ///
		i.aggressortype i.purpose i.indconcur policymakertype##policymakerconcur ///
		female republican7  college white age task choice i.perceivedlikely, vce(cluster caseid)
eststo conflikely

esttab confBase conflikely  ///
	using AppendixConjointQualtricsOLSConfidenceSevereLikely.tex, ///
	label replace  ///
	interaction(" X ") wrap  onecell compress ///
	mtitles("Attribution (Base)" "Attribution (Sector)" ) ///
	title("By View of Sectoral Vulnerability") longtable
	

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* By Threat and Warmth, OLS/Confident + Severe 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
	
	
*** Confident

drop if aggressororigin == 5

	
quietly reg confident ///
			white age college female republican7 ///
			i.target i.economic i.death i.confidence ///
			i.aggressortype b1.aggressororigin i.purpose i.indconcur ///
			i.policymakertype##i.policymakerconcur ///
			task choice ///
			, vce(cluster caseid)
eststo confAdjBase
	
quietly reg confident ///
			white age college female republican7 ///
			i.target i.economic i.death i.confidence ///
			i.aggressortype b1.aggressororigin  i.purpose i.indconcur ///
			i.policymakertype##i.policymakerconcur ///
			task choice ///
			threat, vce(cluster caseid) 
eststo confThreat

quietly reg confident ///
			white age college female republican7 ///
			i.target i.economic i.death i.confidence ///
			i.aggressortype b1.aggressororigin  i.purpose i.indconcur ///
			i.policymakertype##i.policymakerconcur ///
			task choice ///
			warmth, vce(cluster caseid) 
eststo confWarmth

quietly reg confident ///
			white age college female republican7 ///
			i.target i.economic i.death i.confidence ///
			i.aggressortype b1.aggressororigin  i.purpose i.indconcur ///
			i.policymakertype##i.policymakerconcur ///
			task choice ///
			threat warmth, vce(cluster caseid) 
eststo confThreatWarmth

quietly reg confident ///
			white age college female republican7 ///
			i.target i.economic i.death i.confidence ///
			i.aggressortype b1.aggressororigin  i.purpose i.indconcur ///
			i.policymakertype##i.policymakerconcur ///
			task choice ///
			threat warmth if democrat7 == 1, vce(cluster caseid) 
eststo confThreatWarmthDem

quietly reg confident ///
			white age college female republican7 ///
			i.target i.economic i.death i.confidence ///
			i.aggressortype b1.aggressororigin  i.purpose i.indconcur ///
			i.policymakertype##i.policymakerconcur ///
			task choice ///
			threat warmth if republican7 == 1, vce(cluster caseid) 
eststo confThreatWarmthRep

esttab confAdjBase confThreat  ///
	confWarmth confThreatWarmth ///
	confThreatWarmthDem confThreatWarmthRep ///
	using AppendixConjointQualtricsOLSConfidenceWarmthThreat.tex, ///
	label replace   ///
	interaction(" X ")   longtable ///
	mtitles("Base" "Threat" "Warmth" ///
	 "Threat + Warmth" "Dem" "Rep") ///
	 title("Including Perceived Warmth and Threat") ///
	 addnote("First wave did not include question about hospital vulnerability. Major corporations and banks treated interchangeably.")

log close
